cmake_minimum_required(VERSION 3.0.2)
project(rads)


file(GLOB HCNET_LIBS "include/3rdparty/hcnet_sdk/lib/*.so*")
file(GLOB HCNET_LIBS_COM "include/3rdparty/hcnet_sdk/lib/HCNetSDKCom/*.so")
 message(STATUS,"path : ${HCNET_LIBS}")

find_package(catkin REQUIRED COMPONENTS
        roscpp
        rospy
        std_msgs
        sensor_msgs
        geometry_msgs
        nav_msgs
        message_generation
        serial
        pcl_ros
        pcl_conversions
)

find_package(yaml-cpp REQUIRED) 
## 添加PCl的包依赖
find_package(PCL 1.8 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS} ${yaml-cpp_INCLUDE_DIRS} /usr/include/rapidxml )
## 添加sqlite3的包依赖
find_package(PkgConfig REQUIRED)
pkg_check_modules(SQLITE3 sqlite3)

pkg_check_modules(PROJ REQUIRED proj)

add_message_files(
        FILES
        rads_cmd.msg
        rads_apis.msg
        rads_scmd.msg
        rads_scmdret.msg
        rads_trackext.msg
        rads_acks.msg
        rads_guard.msg
        rads_version.msg
        rads_versions.msg
        rads_log.msg
        rads_driving.msg
        rads_camera.msg
        
)
find_package(RapidJSON REQUIRED)
include_directories(${RAPIDJSON_INCLUDE_DIRS})
## Generate services in the 'srv' folder
# add_service_files(
#   FILES
#   Service1.srv
#   Service2.srv
# )

## Generate actions in the 'action' folder
# add_action_files(
#   FILES
#   Action1.action
#   Action2.action
# )

## Generate added messages and services with any dependencies listed here
generate_messages(
        DEPENDENCIES
        std_msgs
        geometry_msgs
        nav_msgs
)

catkin_package(
        INCLUDE_DIRS include/rads
        INCLUDE_DIRS include/3rdparty/hcnet_sdk/include
        #  LIBRARIES rads
        CATKIN_DEPENDS roscpp rospy std_msgs message_runtime
        #  DEPENDS system_lib
)


include_directories(
        include/rads
        ${catkin_INCLUDE_DIRS}
        ${SQLITE3_INCLUDE_DIRS}
        include/3rdparty/hcnet_sdk/include  # 添加 HCNet SDK 头文件路径

)
# 确保库文件路径正确
link_directories(
  include/3rdparty/hcnet_sdk/lib
  include/3rdparty/hcnet_sdk/lib/HCNetSDKCom
)
## Declare a C++ library
# add_library(${PROJECT_NAME}
#   src/${PROJECT_NAME}/rads.cpp
# )
if (1)
    add_executable(rads_rtk src/rads_rtk.cpp)
    add_executable(rads_tbox src/rads_tbox.cpp)
    add_executable(rads_drive src/rads_drive.cpp)
    add_executable(rads_guard src/rads_guard.cpp)
    add_executable(rads_slam src/rads_slam.cpp)
    add_executable(rads_map src/rads_map.cpp)
    add_executable(rads_api src/rads_api.cpp)
    add_executable(rads_business src/rads_business.cpp)
    add_executable(rads_database src/rads_database.cpp)
    add_executable(rads_camera src/rads_camera.cpp)


    target_link_libraries(rads_rtk
            ${catkin_LIBRARIES}
            pthread
            ssl
            crypto
            
    )

    target_link_libraries(rads_tbox
            ${catkin_LIBRARIES}
            pthread
            ssl
            crypto
             
    )

    target_link_libraries(rads_drive
            ${catkin_LIBRARIES}
            pthread
            ssl
            crypto
             
    )

    target_link_libraries(rads_guard
            ${catkin_LIBRARIES}
            pthread
            ssl
            crypto
             
    )

    target_link_libraries(rads_slam
            ${catkin_LIBRARIES}
            pthread
            ssl
            crypto
            ${PROJ_LIBRARIES} 
             

    )

    target_link_libraries(rads_map
            ${catkin_LIBRARIES}
            ${PCL_LIBRARIES}
            pthread
            ssl
            crypto
             
    )

    target_link_libraries(rads_api
            ${catkin_LIBRARIES}
            pthread
            ssl
            crypto
            yaml-cpp
             
    )

    target_link_libraries(rads_business
            ${catkin_LIBRARIES}
            ${SQLITE3_LIBRARIES}
            ${HCNET_LIBS}
            ${HCNET_LIBS_COM}
            pthread
            ssl
            crypto
            z  # 显式链接系统 zlib 库
             
    )

    target_link_libraries(rads_database
            ${catkin_LIBRARIES}
            ${SQLITE3_LIBRARIES}
            pthread
            ssl
            crypto
             
    )
     target_link_libraries(rads_camera
            ${catkin_LIBRARIES}
            ${SQLITE3_LIBRARIES}
            pthread
            ssl
            crypto
             
    )
    ## 设置安装目标
    install(TARGETS
            rads_guard
            RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
    )
    install(TARGETS
            rads_api
            RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
    )
    install(TARGETS
            rads_rtk
            RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
    )
    install(TARGETS
            rads_tbox
            RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
    )
    install(TARGETS
            rads_drive
            RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
    )
    install(TARGETS
            rads_slam
            RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
    )
    install(TARGETS
            rads_map
            RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
    )
    install(TARGETS
            rads_business
            RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
    )
    install(TARGETS
            rads_database
            RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
    )
    install(DIRECTORY launch/
            DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
    )
    install(DIRECTORY ota/
            DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/ota
    )
    install(DIRECTORY etc/
            DESTINATION ${CATKIN_PACKAGE_ETC_DESTINATION}
            FILES_MATCHING PATTERN "*"
    )
endif ()